<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jquery设置文本框样式</title>
    <script src="jquery-3.5.1/jquery-3.5.1/jquery-3.5.1.js"></script>
    <script>
        $(function(){
            $("#username").focus(function(){
                $(this).addClass("username_focus");
            });
            $("#username").blur(function(){
                $(this).removeClass("username_focus");
            });
        });
    </script>
    <style>
        .username_focus{
            border: 1px black solid;
            background-color: #CAE1FF;
        }

    </style>
</head>
<body>
    姓名：<input type="text" id="username">
    <input type="submit" value="提交">
</body>
</html>